package com.xtoneict.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xtoneict.auth.entity.DayDetail;
import com.xtoneict.auth.mapper.DayDetailMapper;
import com.xtoneict.auth.service.IDayDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DayDetailServiceImpl extends ServiceImpl<DayDetailMapper, DayDetail> implements IDayDetailService {
    @Autowired
    private DayDetailMapper dayDetailMapper;

    /**
     * 计算某一天的总工时
     * @return
     */
    public double countToTalWorkTimeOneDay(Integer employeeId, Integer yearMonthId, Integer day){
        QueryWrapper<DayDetail> dayDetailQueryWrapper = new QueryWrapper<>();
        dayDetailQueryWrapper.eq("employee_id", employeeId);
        dayDetailQueryWrapper.eq("year_month_id", employeeId);
        dayDetailQueryWrapper.eq("day", day);

        List<DayDetail> dayDetails = dayDetailMapper.selectList(dayDetailQueryWrapper);

        double total = 0;
        for (DayDetail dayDetail : dayDetails){
            total += dayDetail.getWorkTime();
        }

        return total;
    }
}
